package com.example.mapper;

import com.example.pojo.Emp;
import com.example.pojo.EmpQueryParam;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
* @Auther: Sun
* @Date: 2025/9/16 - 09 - 16 - 15:41
* @Description: com.example.mapper
*/
@Mapper
public interface EmpMapper {
    //原始分页查询
//    @Select("select count(*) from emp e left join dept d on e.dept_id=d.id")
//    public Long count();
//    @Select("select e.* , d.name deptName from emp e left join dept d on e.dept_id = d.id order by e.update_time desc limit #{start}, #{pageSize}")
//    public List<Emp> list(Integer start,Integer pageSize);
//}
    //优化分页查询
    //@Select("select e.* , d.name deptName from emp e left join dept d on e.dept_id = d.id order by e.update_time desc ")
//
    public List<Emp> list(EmpQueryParam empQueryParam);
    @Options(useGeneratedKeys = true,keyProperty = "id")//设置主键回填
    @Insert("insert into emp(username,name,gender,phone,job,salary,image,entry_date,dept_id,create_time,update_time)" +
            "values(#{username},#{name},#{gender},#{phone},#{job},#{salary},#{image},#{entryDate},#{deptId},#{createTime},#{updateTime})")
    void insert(Emp emp);

    void deleteids(List<Integer> ids);

    Emp getById(Integer id);

    void updateById(Emp emp);
    List <Map<String,Object>> countEmpJobData();

    List<Map<String, Object>> countEmpGenderData();
@Select("select emp.* from emp where emp.job = 1 order by emp.update_time desc ")
    List<Emp> listAll();

    @Select("select id,username,name from emp where username = #{username} and password = #{password}")
    Emp selectByUserNameAndPassword(Emp emp);
}

